function $fetch(url, type = 'post', body) {
  return new Promise(function(resolve, reject){
    var option = {
      'method': type ,
      'headers': {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      'credentials': 'include',
      //     'body': body?JSON.stringify(body):'',
    };
    if(body && type.toLowerCase()!=='get'){
      option.body = JSON.stringify(body);
    }
    fetch(url, option).then(function (response) {
      if (Math.trunc(response.status / 100) === 2) {  //请求成功
        return response.json();
      } else {
        return Promise.reject(response.statusText);
      }
    }).then(function (result) {
      resolve(result);
    }).catch(function (err) {
      reject(err);
    })
  });
}

function urlEnCode(obj) {
  let param = '';
  for(let [key, value] of Object.entries(obj)){
    if(param.length===0){
      param = key+'='+value;
    }else{
      param += '&'+key+'='+value;
    }
  }
  return encodeURI(param);
}


function GetQueryString(name)
{
  let reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
  let r = window.location.search.substr(1).match(reg);
  return r?decodeURI(r[2]):null;
}
